Added documentation about how to use the unit test runner.
[adiumx.git] / Plugins / Purple Service / DCPurpleZephyrJoinChatViewController.m
blob5adeaebda87de359fa15454525e79cbfdacd489a
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "DCPurpleZephyrJoinChatViewController.h"
18 #import "DCJoinChatWindowController.h"
19 #import <Adium/AIAccount.h>
21 @interface DCPurpleZephyrJoinChatViewController (PRIVATE)
22 - (void)validateEnteredText;
23 @end
25 @implementation DCPurpleZephyrJoinChatViewController
27 - (NSString *)nibName
29         return @"DCPurpleZephyrJoinChatView";
32 - (void)configureForAccount:(AIAccount *)inAccount
34         [self validateEnteredText];
36         [[view window] makeFirstResponder:textField_class];
37         
38         [super configureForAccount:inAccount];
42  Zephyr uses "class" "instance" and "recipient".  Instance and Recipient are optional and will become "*" if
43  they are not specified; we show this default value automatically for clarity.
44  */
46 - (void)joinChatWithAccount:(AIAccount *)inAccount
47 {       
48         NSString                        *class;
49         NSString                        *instance;
50         NSString                        *recipient;
51         NSDictionary            *chatCreationInfo;
52         
53         class = [textField_class stringValue];
54         instance = [textField_instance stringValue];
55         recipient = [textField_recipient stringValue];
56         
57         if (!instance || ![instance length]) instance = @"*";
58         if (!recipient || ![recipient length]) recipient = @"*";
59         
60         if (class && [class length]) {
61                 NSString        *name;
62                 //The chatCreationInfo has keys corresponding to the GHashTable keys and values to match them.
63                 chatCreationInfo = [NSMutableDictionary dictionaryWithObject:class
64                                                                                                                           forKey:@"class"];
66                 //The chatCreationInfo has keys corresponding to the GHashTable keys and values to match them.
67                 chatCreationInfo = [NSDictionary dictionaryWithObjectsAndKeys:class,@"class",instance,@"instance",recipient,@"recipient",nil];
68                 
69                 name = [NSString stringWithFormat:@"%@,%@,%@",class,instance,recipient];
70                 
71                 [self doJoinChatWithName:name
72                                            onAccount:inAccount
73                                 chatCreationInfo:chatCreationInfo
74                                 invitingContacts:nil
75                    withInvitationMessage:nil];
76         }
79 //Entered text is changing
80 - (void)controlTextDidChange:(NSNotification *)notification
82         if ([notification object] == textField_class) {
83                 [self validateEnteredText];
84         }
87 - (void)validateEnteredText
89         NSString *class = [textField_class stringValue];
90         BOOL enabled = NO;
91         
92         if (class && [class length]) {
93                 enabled = YES;
94         }
95         
96         if (delegate)
97                 [(DCJoinChatWindowController *)delegate setJoinChatEnabled:enabled];
100 @end